﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace University.Workshop.Presentation.Cistern.Modify
{
    /// <summary>
    /// Interaction logic for PageFirstStepModifyCistern.xaml
    /// </summary>
    public partial class PageFirstStepModifyCisternView : Page, Presenters.Cistern.Modify.IFirstStepForModifyCistern
    {
       Presenters.Cistern.Modify.PresenterModifyCistern pInternal;
       Presenters.Cistern.Modify.PresenterModifyFirstStep pModifyFirstStep;
        public PageFirstStepModifyCisternView(Presenters.Cistern.Modify.PresenterModifyCistern pExternal)
        {
            InitializeComponent();
            pInternal = pExternal;
            pModifyFirstStep = new Presenters.Cistern.Modify.PresenterModifyFirstStep(this);
        }

        public string PersonId
        {
            get
            {
                return PersonCiTxt.Text;
            }
            set
            {
                PersonCiTxt.Text = value;
            }
        }

        public string PersonNames
        {
            get
            {
                return PersonNamesTxt.Text;
            }
            set
            {
                PersonNamesTxt.Text = value;
            }
        }

        public string PersonLastNames
        {
            get
            {
                return PersonLastNamesTxt.Text;
            }
            set
            {
                PersonLastNamesTxt.Text = value;
            }
        }

        public string PersonNewPhones
        {
            get
            {
                return PersonPhonesTxt.Text;
            }
            set
            {
                PersonPhonesTxt.Text = value;
            }
        }

        public List<string> PersonPhones
        {
            set { PersonPhonesList.ItemsSource = value; }
        }

        public Model.Cistern CisternToModify
        {
            get;
            set;
        }

        public void Update()
        {
            pModifyFirstStep.UpdateData();
        }

        public string SystemMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                MessageBox.Show(value);
            }
        }

        public string ErrorMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                MessageBox.Show(value);
            }
        }

        public void ChargeDataToBasic()
        {
            pModifyFirstStep.ChargeDataPerson();
        }

        public void GoNextPage()
        {

        }

        public void GoBackPage()
        {
            pInternal.GoStepOne();
        }

        #region validations
        private void PersonPhonesTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            string temporal = ((TextBox)sender).Text+ e.Text;
            foreach (char ch in e.Text)
            {
                    e.Handled = !(char.IsDigit(ch) || ch.Equals(','));
            }
        }

        private void PersonPhonesTxt_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                e.Handled = true;
            }
        }

        private void CantCupyPasteOrCut(object sender, CanExecuteRoutedEventArgs e)
        {
            if(e.Command==ApplicationCommands.Copy)
                e.Handled=true;
            if(e.Command==ApplicationCommands.Cut)
                e.Handled=true;
            if (e.Command == ApplicationCommands.Paste)
                e.Handled = true;
        }

        private void PersonPhonesTxt_TextChanged(object sender, TextChangedEventArgs e)
        {
            pModifyFirstStep.ChargePhonesToList();
        }

        private void PersonCiTxt_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            pModifyFirstStep.VerifyIfDriverIdExist();
        }

        private void JustLettersTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            string temporal = ((TextBox)sender).Text + e.Text;
            foreach (char ch in e.Text)
            {
                e.Handled = !char.IsLetter(ch);
            }
        }
        #endregion

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "Registrar Persona";
        }

        string Presenters.Cistern.Modify.IFirstStepForModifyCistern.PersonId
        {
            get
            {
                return PersonCiTxt.Text;
            }
            set
            {
                PersonCiTxt.Text = value;
            }
        }
    }
}
